<?php

/**
 * Calcualtes only shipping tax on checkout shipping page.
 */
class shipping_tax_checkout_shipping_e_tax extends a_event_subscriber {

    public function __construct() {
        parent::__construct();
    }

    public function fire($args = null) {
        if (service_l_core::get_global_setting("tax_on_shipping") === "1") {
            logger::i()->info("Firing for saving SHIPPING tax on order", 'event', 'tax');
            $order_obj = @$args['order_obj'];
            if (is_a($order_obj, "order_m_order") && $order_obj !== NUll) {
                $tax_service = new service_l_tax();
                $calculated_grouped_tax_amount = $tax_service->calculate_order_shipping_tax($order_obj);
                if ($calculated_grouped_tax_amount) {
                    $tax_service->save_order_shipping_tax($order_obj, $calculated_grouped_tax_amount);
                }
                unset($order_obj);
                unset($tax_service);
            } else {
                logger::i()->error("Could not SHIPPING tax cause order obj is NULL/invalid", 'event', 'tax');
            }
        }
        return;
    }

    public function get_event_name() {
        return module_u_checkout_shipping::EVENT_CHECKOUT_SHIPPING_EXECUTED;
    }

}

?>